package com.simpou.commons.web.model;

import com.simpou.commons.utils.lang.Conditionals;

import javax.ws.rs.core.MultivaluedMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author jonas1
 * @version 23/09/13
 * @since 23/09/13
 */
public class MultivaluedMapImpl<T, E> extends HashMap<T, List<E>> implements MultivaluedMap<T, E> {
    @Override
    public void putSingle(T s, E s2) {
        super.put(s, Arrays.asList(s2));
    }

    @Override
    public void add(T s, E s2) {
        putSingle(s,s2);
    }

    @Override
    public E getFirst(T s) {
        final E ret;
        if(containsKey(s)){
            List<E> list = get(s);
            if(Conditionals.isEmpty(list)){
                ret = null;
            }else{
                ret = list.get(0);
            }
        }else{
            ret = null;
        }
        return ret;
    }
}
